package com.basic.business.memoRelation.service.impl;

import com.basic.common.constant.CacheConstants;
import com.basic.common.core.redis.RedisCacheUtils;
import org.springframework.stereotype.Service;
import com.basic.common.core.service.impl.BaseServiceImpl;
import com.basic.business.memoRelation.domain.TOrdersMemoRelation;
import com.basic.business.memoRelation.service.ITOrdersMemoRelationService;
import com.basic.business.memoRelation.mapper.TOrdersMemoRelationMapper;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * 备注关系Service业务层处理
 *
 * @author zhaoxy_jn@163.com
 */
@Service
public class TOrdersMemoRelationServiceImpl extends BaseServiceImpl<TOrdersMemoRelationMapper, TOrdersMemoRelation> implements ITOrdersMemoRelationService {

    @Resource
    private TOrdersMemoRelationMapper tOrdersMemoRelationMapper;

    @PostConstruct
    public void init(){
        resetMemoRelationCache();
    }

    public List<TOrdersMemoRelation> getNormalMemoRelation() {
        return tOrdersMemoRelationMapper.getNormalMemoRelation();
    }

    @Override
    public int updateStatusByIds(String[] ids, String status) {
        return tOrdersMemoRelationMapper.updateStatusByIds(ids, status);
    }

    @Override
    public void resetMemoRelationCache() {
        // 清空缓存
        RedisCacheUtils.clearCache(CacheConstants.MEMO_RELATION_REDIS_KEY + "*");
        // 加载缓存
        RedisCacheUtils.setCacheObject(CacheConstants.MEMO_RELATION_REDIS_KEY, getNormalMemoRelation());
    }
}
